package com.yunbao.hujin.mychoosealbum.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.yunbao.hujin.mychoosealbum.utils.GlideUtil;

import java.util.ArrayList;

/**
 * 选中图片查看大图 on 2017/12/1.
 */

public class AdapterShowChooseImg extends PagerAdapter{

    private Context context;
    private ArrayList<String> listPath;     //图片路径
    private RelativeLayout root;

    public AdapterShowChooseImg(Context context, ArrayList<String> listPath, RelativeLayout root) {
        this.context = context;
        this.listPath = listPath;
        this.root = root;
    }

    @Override
    public int getCount() {
        return listPath.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        final ImageView photoView = new ImageView(container.getContext());
        photoView.setScaleType(ImageView.ScaleType.CENTER);

        GlideUtil.showImgCenterBitmap(context, listPath.get(position))
//                .listener(new RequestListener() {
//                    @Override
//                    public boolean onException(Exception e, Object model, Target target, boolean isFirstResource) {
//                        photoView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
//                        return false;
//                    }
//
//                    @Override
//                    public boolean onResourceReady(Object resource, Object model, Target target, boolean isFromMemoryCache, boolean isFirstResource) {
//                        return false;
//                    }
//                })
                .into(photoView);

        container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        return photoView;

        //有lib版本
//        PhotoView photoView = new PhotoView(container.getContext(), root);
//        GlideUtil.showLocalImgFitCenterAsBitmap(context, listPath.get(position))
//                .listener(new GlideListener(photoView, GlideListener.SETSCALTYPE))
//                .into(photoView);
//        container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
//        return photoView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

}
